/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dressingsocial.controller;

import com.dressingsocial.model.Dressing;
import com.dressingsocial.model.Opinion;
import com.dressingsocial.model.User;
import com.dressingsocial.service.DressingService;
import com.dressingsocial.service.OpinionService;
import com.dressingsocial.service.UserService;
import java.util.List;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author hayate
 */
@Controller
@RequestMapping(value = "/me")
public class MeController {
    @Autowired
    private UserService userService;
    
    @Autowired
    private DressingService dressingService;
    
    @Autowired
    private OpinionService opinionService;
    
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public String mypage(Model model) {
        String email = (String)SecurityUtils.getSubject().getPrincipal();
        User user = userService.findByEmail(email);
        List<User> users = userService.findRecommendedUsers();
        model.addAttribute("user", user);
        model.addAttribute("users", users);
        List<Dressing> latestDressings = dressingService.findLatestDressings();
        List<Dressing> hotestDressings = dressingService.findHotestDressings();
        model.addAttribute("latestDressings", latestDressings);
        model.addAttribute("hotestDressings", hotestDressings);
        List<Opinion> hotestOpinions = opinionService.findHotestOpinions();
        model.addAttribute("hotestOpinions", hotestOpinions);
        return "mypage";
    }
}
